{{^controllerOnly}}
{{#authMethods.0}}
{{#isOAuth}}
        if (!securityAPIUtils.isRequestTokenValid(request, "{{name}}")) {
            return {{#supportAsync}}CompletableFuture.supplyAsync(play.mvc.Results::unauthorized){{/supportAsync}}{{^supportAsync}}unauthorized(){{/supportAsync}};
        }

{{/isOAuth}}
{{/authMethods.0}}
{{^returnType}}
{{#supportAsync}}
        CompletableFuture<Result> result = CompletableFuture.supplyAsync(() -> {
        try {
{{/supportAsync}}
{{/returnType}}
        {{#returnType}}{{#supportAsync}}CompletionStage<{{>returnTypesNoVoid}}> stage = {{/supportAsync}}{{^supportAsync}}{{>returnTypesNoVoid}} obj = {{/supportAsync}}{{/returnType}}{{^returnType}}{{#supportAsync}}    {{/supportAsync}}{{/returnType}}{{^useInterfaces}}imp.{{/useInterfaces}}{{operationId}}(request{{#hasParams}}, {{/hasParams}}{{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}{{#supportAsync}}.thenApply(obj -> { {{/supportAsync}}{{/returnType}}{{^supportAsync}};{{/supportAsync}}{{#supportAsync}}{{^returnType}};{{/returnType}}{{/supportAsync}}
{{#returnType}}
{{^isResponseFile}}
{{^returnTypeIsPrimitive}}
{{#useBeanValidation}}

        if (configuration.getBoolean("useOutputBeanValidation")) {
            {{#isArray}}
            for ({{{returnType}}} curItem : obj) {
                OpenAPIUtils.validate(curItem);
            }
            {{/isArray}}
            {{#isMap}}
            for (Map.Entry<String, {{{returnType}}}> entry : obj.entrySet()) {
                OpenAPIUtils.validate(entry.getValue());
            }
            {{/isMap}}
            {{^returnContainer}}
            OpenAPIUtils.validate(obj);
            {{/returnContainer}}
        }

{{/useBeanValidation}}
{{/returnTypeIsPrimitive}}
{{/isResponseFile}}
{{#supportAsync}}
        return obj;
    });
{{/supportAsync}}
{{/returnType}}
{{#returnType}}
{{#supportAsync}}
return stage.thenApply(obj -> {
{{/supportAsync}}
{{^isResponseFile}}
{{#supportAsync}}    {{/supportAsync}}        JsonNode result = mapper.valueToTree(obj);

{{#supportAsync}}    {{/supportAsync}}        return ok(result);
{{/isResponseFile}}
{{#isResponseFile}}

{{#supportAsync}}    {{/supportAsync}}        return ok(obj);
{{/isResponseFile}}
{{/returnType}}
{{^returnType}}
{{#supportAsync}}
        } catch (Exception e) {
            throw new CompletionException(e);
        }
        return ok();
    });
    return result;
{{/supportAsync}}
{{^supportAsync}}
        return ok();
{{/supportAsync}}
{{/returnType}}
{{#returnType}}
{{#supportAsync}}
    });
{{/supportAsync}}
{{/returnType}}
{{/controllerOnly}}
{{#controllerOnly}}
        return ok();
{{/controllerOnly}}
